from collections import deque

"""
列表函数的使用
append
count
index
reverse
sort
pop
"""


def function_test():
    fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
    print(fruits.count('apple'))
    print(fruits.count('tangerine'))
    print(fruits.index('banana'))
    print(fruits.index('banana', 4))  # Find next banana starting a position 4
    fruits.reverse()
    print(fruits)
    fruits.append('grape')
    print(fruits)
    fruits.sort()
    print(fruits)
    fruits.pop()
    print(fruits)


"""
列表作为栈使用,栈是先进后出，后进先出
"""


def stack_test():
    stack = [3, 4, 5]
    stack.append(6)
    stack.append(7)
    print(stack)

    stack.pop()
    print(stack)

    stack.pop()
    stack.pop()

    print(stack)


"""
列表作为队列使用，队列是先进先出
"""


def queue_test():
    queue = deque(["Eric", "John", "Michael"])
    queue.append("Terry")  # Terry arrives
    queue.append("Graham")  # Graham arrives
    print(queue)
    queue.popleft()  # The first to arrive now leaves
    print(queue)
    queue.popleft()  # The second to arrive now leaves

    print(queue)  # Remaining queue in order of arrival


"""
列表推导式 , 向列表中加入元素来进行创建
"""


def creat_test():
    squares = []
    for x in range(10):
        squares.append(x ** 2)
    print(squares)

    mapTest = map(lambda x2: x2 ** 2, range(10))

    print(mapTest)
    squares = list(mapTest)
    print(squares)
    # 这个语法好喜欢
    squares = [x ** 2 for x in range(10)]
    print(squares)


"""
主函数使用名称来进行判断，入口main程序
"""
if __name__ == "__main__":
    # function_test()
    # stack_test()
    # queue_test()
    creat_test()
